<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./skin/pub/css/font-awesome.min.css">
    <link rel="stylesheet" href="./skin/pub/css/bootstrap.css">
    <link rel="stylesheet" href="./skin/css/examinations.css">
    <link rel="stylesheet" type="text/css" href="./skin/css/styles.css">
    <title>精准测评</title>
</head>
<body>
<div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">
            <img alt="X+" src="./skin/img/logo.png">
        </a>
    </div>
</div>
<div class="wrapper">
    <div class="container">
        <h1>Welcome</h1>
        <form class="form">
            <input type="text" id="username" placeholder="用户名">
            <input type="password" id="pwd" placeholder="密码">
            <button type="submit" id="login-button">登录</button>
        </form>
    </div>
    <ul class="bg-bubbles">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>

</div>
<script src="./skin/pub/js/jquery-1.11.3.min.js"></script>
<script src="./skin/pub/js/html5.js"></script>
<script src="./skin/pub/layer/layer.js"></script>
<script>
    $('#login-button').click(function(event){
        event.preventDefault();
        var username = $("#username").val();
        if(username.length>0){
            $('form').fadeOut(500);
            $.ajax({
                type:"POST",
                url: "http://vip.classba.com/crm/index.php?m=evaluate&a=verify_login",
                data: {
                    "username":username,
                    "pwd":$("#pwd").val()
                },
                dataType: "json",
                success: function (data) {
                    if (data.status) {
                        setCookie("username",$("#username").val(),"h1");
                        setCookie("uid",data.uid,"h1");
                        layer.msg('登录成功', {
                            time: 1000, //20s后自动关闭
                        },function(){
                            window.open("./panelindex.html","_self")
                        });
                    } else {
                        $('form').fadeIn(500);
                        layer.msg("用户名和密码不匹配，如有疑问请致电400-123-9988");
                    }
                },
                complete:function(){
                    setCookie("username",$("#username").val(),"h1");
                },
                error: function (XMLHttpRequest,data) {
                    layer.alert(JSON.stringify(data)+"登陆失败");
                }
            })
        }else{
            layer.alert("用户名不能为空！");
        }
        //使用示例
    });
    //写cookies
//    function setCookie(c_name, value, expiredays){
//        var exdate=new Date();
//        exdate.setDate(exdate.getDate() + expiredays);
//        document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
//    }
    function setCookie(name,value,time){
        var strsec = getsec(time);
        var exp = new Date();
        exp.setTime(exp.getTime() + strsec*1);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }
    function getsec(str){
        var str1=str.substring(1,str.length)*1;
        var str2=str.substring(0,1);
        if (str2=="s"){
            return str1*1000;
        }else if (str2=="h"){
            return str1*60*60*1000;
        }else if (str2=="d"){
            return str1*24*60*60*1000;
        }
    }
    //读取cookies
    function getCookie(name)
    {
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

        if(arr=document.cookie.match(reg))

            return (arr[2]);
        else
            return null;
    }

    //删除cookies
    function delCookie(name)
    {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getCookie(name);
        if(cval!=null)
            document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }

    $("#login").click(function (){
        $.ajax({
            type:"POST",
            url: "http://vip.classba.com/crm/index.php?m=evaluate&a=verify_login",
            data: {
                "username":$("#username").val(),
                "pwd":$("pwd").val()
            },
            dataType: "json",
            success: function (data) {
                console.log(JSON.stringify(data));
                if (data.status) {
                    setCookie("uid",data.uid);
                    window.open("./report.html","_self")
                } else {
                    layer.alert("用户名和密码不匹配，如有疑问请致电 400-123-9988");
                }
            },
            error: function (XMLHttpRequest,data) {
                layer.alert(JSON.stringify(data)+"提交失败");
            }
        })
    })
</script>
</body>
</html>